package com.mrzhou.job.controller;

import com.mrzhou.core.tool.api.R;
import com.mrzhou.core.tool.utils.BeanUtil;
import com.mrzhou.job.entity.SchedulerJob;
import com.mrzhou.job.service.ISchedulerJobService;
import com.mrzhou.job.vo.req.CreateSchedulerJobReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("job")
@Api("定时器任务接口")
public class SchedulerJobController {

    @Autowired
    private ISchedulerJobService schedulerJobService;

    @PostMapping("create")
    @ApiOperation("创建定时器任务")
    public R<String> createJob(@RequestBody @Validated CreateSchedulerJobReq req) {
//        SchedulerJob job = new SchedulerJob();
//        job.setId(99999L);
//        job.setJobClass(TestTask.class.getName());
//        job.setCronExpression("0 0/1 * * *  ? *");
//        SchedulerUtil.createJob(scheduler, job);
        SchedulerJob schedulerJob = BeanUtil.copy(req, SchedulerJob.class);
        schedulerJobService.saveOrUpdateJob(schedulerJob);
        return R.success("创建定时器成功");
    }


}
